home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / ktoolbar.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  35.2 KB  |  1,129 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 2000 Reginald Stadlbauer (reggie@kde.org)
  3.     (C) 1997, 1998 Stephan Kulow (coolo@kde.org)
  4.     (C) 1997, 1998 Sven Radej (radej@kde.org)
  5.     (C) 1997, 1998 Mark Donohoe (donohoe@kde.org)
  6.     (C) 1997, 1998 Matthias Ettrich (ettrich@kde.org)
  7.     (C) 1999, 2000 Kurt Granroth (granroth@kde.org)
  8.  
  9.     This library is free software; you can redistribute it and/or
  10.     modify it under the terms of the GNU Library General Public
  11.     License version 2 as published by the Free Software Foundation.
  12.  
  13.     This library is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.     Library General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU Library General Public License
  19.     along with this library; see the file COPYING.LIB.  If not, write to
  20.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21.     Boston, MA 02110-1301, USA.
  22.     */
  23.  
  24. #ifndef KTOOLBAR_H
  25. #define KTOOLBAR_H
  26.  
  27. #include <qtoolbar.h>
  28. #include <qmainwindow.h>
  29. #include <qcombobox.h>
  30. #include <qmap.h>
  31. #include <qptrlist.h>
  32. #include <qguardedptr.h>
  33. #include <qframe.h>
  34. #include <qiconset.h>
  35.  
  36. #include <kglobal.h>
  37.  
  38. class QDomElement;
  39. class QSize;
  40. class QPixmap;
  41. class QPopupMenu;
  42. class QStringList;
  43. class QDomDocument;
  44. class QTimer;
  45.  
  46. class KLineEdit;
  47. class KToolBar;
  48. class KToolBarButton;
  49. class KToolBoxManager;
  50. class KAnimWidget;
  51. class KPopupMenu;
  52. class KInstance;
  53. class KComboBox;
  54. class KXMLGUIClient;
  55.  
  56. class KToolBarPrivate;
  57.  
  58. class KDEUI_EXPORT KToolBarSeparator : public QFrame
  59. {
  60.     Q_OBJECT
  61. public:
  62.     KToolBarSeparator( Orientation, bool l, QToolBar *parent, const char* name=0 );
  63.  
  64.     QSize sizeHint() const;
  65.     Orientation orientation() const { return orient; }
  66.     QSizePolicy sizePolicy() const;
  67.     bool showLine() const { return line; }
  68. public slots:
  69.    void setOrientation( Orientation );
  70. protected:
  71.     void styleChange( QStyle& );
  72.     void drawContents( QPainter* );
  73. private:
  74.     Orientation orient;
  75.     bool line;
  76. };
  77.  
  78.  
  79.  /**
  80.   * @short Floatable toolbar with auto resize.
  81.   *
  82.   * A KDE-style toolbar.
  83.   *
  84.   * KToolBar can be dragged around in and between different docks.
  85.   *
  86.   * A KToolBar can contain all sorts of widgets.
  87.   *
  88.   * KToolBar can be used as a standalone widget, but KMainWindow
  89.   * provides easy factories and management of one or more toolbars.
  90.   * Once you have a KToolBar object, you can insert items into it with the
  91.   * insert... methods, or remove them with the removeItem() method. This
  92.   * can be done at any time; the toolbar will be automatically updated.
  93.   * There are also many methods to set per-child properties like alignment
  94.   * and toggle behavior.
  95.   *
  96.   * KToolBar uses a global config group to load toolbar settings on
  97.   * construction. It will reread this config group on a
  98.   * KApplication::appearanceChanged() signal.
  99.   *
  100.   * @author Reginald Stadlbauer <reggie@kde.org>, Stephan Kulow <coolo@kde.org>, Sven Radej <radej@kde.org>.
  101.   */
  102.  
  103. class KDEUI_EXPORT KToolBar : public QToolBar
  104. {
  105.     Q_OBJECT
  106.     Q_ENUMS( IconText BarPosition )
  107.     Q_PROPERTY( IconText iconText READ iconText WRITE setIconText )
  108.     Q_PROPERTY( BarPosition barPos READ barPos WRITE setBarPos )
  109.     Q_PROPERTY( bool fullSize READ fullSize WRITE setFullSize )
  110.     Q_PROPERTY( int iconSize READ iconSize WRITE setIconSize )
  111.     Q_PROPERTY( QString text READ text WRITE setText )
  112.  
  113. public:
  114.     enum IconText{IconOnly = 0, IconTextRight, TextOnly, IconTextBottom};
  115.     /**
  116.      * The state of the status bar.
  117.      * @deprecated
  118.      */
  119.     enum BarStatus{Toggle, Show, Hide};
  120.     /**
  121.    * Possible bar positions.
  122.    */
  123.     enum BarPosition{ Unmanaged, Floating, Top, Bottom, Right, Left, Flat};
  124.  
  125.   /**
  126.    * Normal constructor.
  127.    * This constructor is used by the XML-GUI. If you use it, you need
  128.    * to call QMainWindow::addToolBar to specify the position of the toolbar.
  129.    * So it's simpler to use the other constructor.
  130.    *
  131.    * The toolbar will read in various global config settings for
  132.    * things like icon size and text position, etc.  However, some of
  133.    * the settings will be honored only if @p honorStyle is set to
  134.    * true.  All other toolbars will be IconOnly and use Medium icons.
  135.    *
  136.    * @param parent      The standard toolbar parent (usually a
  137.    * KMainWindow)
  138.    * @param name        The standard internal name
  139.    * @param honorStyle  If true, then global settings for IconSize and IconText will be honored
  140.    * @param readConfig  whether to apply the configuration (global and application-specific)
  141.    */
  142.     KToolBar( QWidget *parent, const char *name = 0, bool honorStyle = false, bool readConfig = true );
  143.  
  144.   /**
  145.    * Constructor for non-XML-GUI applications.
  146.    *
  147.    * The toolbar will read in various global config settings for
  148.    * things like icon size and text position, etc.  However, some of
  149.    * the settings will be honored only if @p honorStyle is set to
  150.    * true.  All other toolbars will be IconOnly and use Medium icons.
  151.    *
  152.    * @param parentWindow The window that should be the parent of this toolbar
  153.    * @param dock        The position of the toolbar. Usually QMainWindow::Top.
  154.    * @param newLine     If true, start a new line in the dock for this toolbar.
  155.    * @param name        The standard internal name
  156.    * @param honorStyle  If true, then global settings for IconSize and IconText will be honored
  157.    * @param readConfig  whether to apply the configuration (global and application-specific)
  158.    */
  159.     KToolBar( QMainWindow *parentWindow, QMainWindow::ToolBarDock dock /*= QMainWindow::Top*/, bool newLine = false,
  160.               const char *name = 0, bool honorStyle = false, bool readConfig = true );
  161.  
  162.   /**
  163.    * Constructor for non-XML-GUI applications.
  164.    *
  165.    * The toolbar will read in various global config settings for
  166.    * things like icon size and text position, etc.  However, some of
  167.    * the settings will be honored only if @p honorStyle is set to
  168.    * true.  All other toolbars will be IconOnly and use Medium icons.
  169.    *
  170.    * @param parentWindow The window that should be the parent of this toolbar
  171.    * @param dock        Another widget than the mainwindow to dock toolbar to.
  172.    * @param newLine     If true, start a new line in the dock for this toolbar.
  173.    * @param name        The standard internal name
  174.    * @param honorStyle  If true, then global settings for IconSize and IconText will be honored
  175.    * @param readConfig  whether to apply the configuration (global and application-specific)
  176.    */
  177.     KToolBar( QMainWindow *parentWindow, QWidget *dock, bool newLine = false,
  178.               const char *name = 0, bool honorStyle = false, bool readConfig = true );
  179.  
  180.   /**
  181.    * Destructor
  182.    */
  183.     virtual ~KToolBar();
  184.  
  185.   /**
  186.    * Insert a button (a KToolBarButton) with a pixmap.  The
  187.    * pixmap is loaded by the button itself based on the global icon
  188.    * settings.
  189.    *
  190.    * You should connect to one or more signals in KToolBar:
  191.    * clicked() , pressed() , released() , or
  192.    * highlighted()  and if the button is a toggle button
  193.    * ( setToggle() ) toggled() .  Those signals have @p id
  194.    * of a button that caused the signal.  If you want to bind a popup
  195.    * to button, see setButton().
  196.    *
  197.    * @param icon    The name of the icon to use as the active pixmap
  198.    * @param id      The id of this button
  199.    * @param enabled Enable or disable the button at startup
  200.    * @param text    The tooltip or toolbar text (depending on state)
  201.    * @param index   The position of the button. (-1 = at end).
  202.    * @param _instance instance this button will belong to
  203.    *
  204.    * @return The item index.
  205.    */
  206.     int insertButton(const QString& icon, int id, bool enabled = true,
  207.              const QString& text = QString::null, int index=-1,
  208.              KInstance *_instance = KGlobal::instance());
  209.  
  210.    /**
  211.    * This is the same as above, but with specified signals and
  212.    * slots to which this button will be connected.
  213.    *
  214.    * You can add more signals with addConnection().
  215.    *
  216.    * @param icon     The name of the icon to use as the active pixmap
  217.    * @param id       The id of this button
  218.    * @param signal   The signal to connect to
  219.    * @param receiver The slot's parent
  220.    * @param slot     The slot to receive the signal specified in that argument.
  221.    * @param enabled  Enable or disable the button at startup
  222.    * @param text     The tooltip or toolbar text (depending on state)
  223.    * @param index    The position of the button. (-1 = at end).
  224.    * @param _instance instance this button will belong to
  225.    *
  226.    * @return The item index.
  227.    */
  228.     int insertButton(const QString& icon, int id, const char *signal,
  229.              const QObject *receiver, const char *slot,
  230.              bool enabled = true, const QString& text = QString::null,
  231.              int index=-1, KInstance *_instance = KGlobal::instance() );
  232.  
  233.   /**
  234.    * Inserts a button (a KToolBarButton) with the specified
  235.    * pixmap.  This pixmap will be used as the "active" one and the
  236.    * disabled and default ones will be autogenerated.
  237.    *
  238.    * It is recommended that you use the insertButton function that
  239.    * allows you to specify the icon name rather then the pixmap
  240.    * itself.  Specifying the icon name is much more flexible.
  241.    *
  242.    * You should connect to one or more signals in KToolBar:
  243.    * clicked() , pressed() , released() , or
  244.    * highlighted()  and if the button is a toggle button
  245.    * ( setToggle() ) toggled() .  Those signals have @p id
  246.    * of a button that caused the signal.  If you want to bind a popup
  247.    * to button, see setButton().
  248.    *
  249.    * @param pixmap  The active pixmap
  250.    * @param id      The id of this button
  251.    * @param enabled Enable or disable the button at startup
  252.    * @param text    The tooltip or toolbar text (depending on state)
  253.    * @param index   The position of the button. (-1 = at end).
  254.    *
  255.    * @return The item index.
  256.    */
  257.     int insertButton(const QPixmap& pixmap, int id, bool enabled = true,
  258.              const QString& text = QString::null, int index=-1 );
  259.  
  260.   /**
  261.    * This is the same as above, but with specified signals and
  262.    * slots to which this button will be connected.
  263.    *
  264.    * You can add more signals with addConnection().
  265.    *
  266.    * @param pixmap   The name of the icon to use as the active pixmap
  267.    * @param id       The id of this button
  268.    * @param signal   The signal to connect to
  269.    * @param receiver The slot's parent
  270.    * @param slot     The slot to receive the signal specified in that argument.
  271.    * @param enabled  Enable or disable the button at startup
  272.    * @param text     The tooltip or toolbar text (depending on state)
  273.    * @param index    The position of the button. (-1 = at end).
  274.    *
  275.    * @return The item index.
  276.    */
  277.     int insertButton(const QPixmap& pixmap, int id, const char *signal,
  278.              const QObject *receiver, const char *slot,
  279.              bool enabled = true, const QString& text = QString::null,
  280.              int index=-1 );
  281.  
  282.   /**
  283.    * Inserts a button with popupmenu.
  284.    *
  285.    * Button will have small
  286.    * triangle. You have to connect to popup's signals. The
  287.    * signals KButton::pressed(), KButton::released(),
  288.    * KButton::clicked() or KButton::doubleClicked() are @p not
  289.    * emmited by
  290.    * this button (see setDelayedPopup() for that).
  291.    * You can add custom popups which inherit QPopupMenu to get popups
  292.    * with tables, drawings etc. Just don't fiddle with events there.
  293.    */
  294.     int insertButton(const QString& icon, int id, QPopupMenu *popup,
  295.              bool enabled, const QString&_text, int index=-1);
  296.  
  297.   /**
  298.    * Inserts a button with popupmenu.
  299.    *
  300.    * Button will have small
  301.    * triangle. You have to connect to popup's signals. The
  302.    * signals KButton::pressed(), KButton::released(),
  303.    * KButton::clicked() or KButton::doubleClicked() are @p not
  304.    * emmited by
  305.    * this button (see setDelayedPopup() for that).
  306.    * You can add custom popups which inherit QPopupMenu to get popups
  307.    * with tables, drawings etc. Just don't fiddle with events there.
  308.    */
  309.     int insertButton(const QPixmap& pixmap, int id, QPopupMenu *popup,
  310.              bool enabled, const QString&_text, int index=-1);
  311.  
  312.   /**
  313.    * Inserts a KLineEdit. You have to specify signals and slots to
  314.    * which KLineEdit will be connected. KLineEdit has all slots QLineEdit
  315.    * has, plus signals KLineEdit::completion and KLineEdit::textRotation
  316.    * KLineEdit can be set to autoresize itself to full free width
  317.    * in toolbar, that is to last right aligned item. For that,
  318.    * toolbar must be set to full width (which it is by default).
  319.    * @see setFullWidth()
  320.    * @see setItemAutoSized()
  321.    * @see KLineEdit
  322.    * @return Item index.
  323.    */
  324.     int insertLined (const QString& text, int id,
  325.              const char *signal,
  326.              const QObject *receiver, const char *slot,
  327.              bool enabled = true,
  328.              const QString& toolTipText = QString::null,
  329.              int size = 70, int index =-1);
  330.  
  331.   /**
  332.    * Inserts a KComboBox with list.
  333.    *
  334.    * Can be writable, but cannot contain
  335.    * pixmaps. By default inserting policy is AtBottom, i.e. typed items
  336.    * are placed at the bottom of the list. Can be autosized. If the size
  337.    * argument is specified as -1, the width of the combobox is automatically
  338.    * computed.
  339.    *
  340.    * @see setFullWidth()
  341.    * @see setItemAutoSized()
  342.    * @see KComboBox
  343.    * @return Item index.
  344.    */
  345.     int insertCombo (const QStringList &list, int id, bool writable,
  346.              const char *signal, const QObject *receiver,
  347.              const char *slot, bool enabled=true,
  348.              const QString& tooltiptext=QString::null,
  349.              int size=70, int index=-1,
  350.              QComboBox::Policy policy = QComboBox::AtBottom);
  351.  
  352.   /**
  353.    * Insert a KComboBox with text.
  354.    *
  355.    * The rest is the same as above.
  356.    * @see setItemAutoSized()
  357.    *
  358.    * @see KComboBox
  359.    * @return Item index.
  360.    */
  361.     int insertCombo (const QString& text, int id, bool writable,
  362.              const char *signal, QObject *receiver,
  363.              const char *slot, bool enabled=true,
  364.              const QString& tooltiptext=QString::null,
  365.              int size=70, int index=-1,
  366.              QComboBox::Policy policy = QComboBox::AtBottom);
  367.  
  368.     /**
  369.      * Inserts a separator into the toolbar with the given @p id.
  370.      * @return the separator's index
  371.      */
  372.     int insertSeparator( int index = -1, int id = -1 );
  373.  
  374.     /**
  375.      * Inserts a line separator into the toolbar with the given @p id.
  376.      * @return the separator's index
  377.      */
  378.     int insertLineSeparator( int index = -1, int id = -1 );
  379.  
  380.   /**
  381.    * Inserts a user-defined widget.  The widget @p must have this
  382.    * toolbar as its parent.
  383.    *
  384.    * Widget must have a QWidget for base class.  Widget can be
  385.    * autosized to full width. If you forget about it, you can get a
  386.    * pointer to this widget with getWidget().
  387.    * @see setItemAutoSized()
  388.    * @return Item index.
  389.    */
  390.     int insertWidget(int id, int width, QWidget *_widget, int index=-1);
  391.  
  392.   /**
  393.    * Inserts an animated widget.  A KAnimWidget will be created
  394.    * internally using the icon name you provide.
  395.    * This will emit a signal (clicked()) whenever the
  396.    * animation widget is clicked.
  397.    *
  398.    * @see animatedWidget()
  399.    *
  400.    * @param id       The id for this toolbar item
  401.    * @param receiver The parent of your slot
  402.    * @param slot     The slot to receive the clicked() signal
  403.    * @param icons    The name of the animation icon group to use
  404.    * @param index    The item index
  405.    *
  406.    * @return The item index
  407.    */
  408.     int insertAnimatedWidget(int id, QObject *receiver, const char *slot,
  409.                  const QString& icons, int index = -1);
  410.  
  411.     /**
  412.    * This will return a pointer to the animated widget with the
  413.    * given @p id, if it exists.
  414.    *
  415.    * @see insertAnimatedWidget
  416.    * @param id The id for the widget you want to get a pointer to
  417.    * @return A pointer to the current animated widget or 0L
  418.    */
  419.     KAnimWidget *animatedWidget( int id );
  420.  
  421.   /**
  422.    * Adds connections to items.
  423.    *
  424.    * It is important that you
  425.    * know the @p id of particular item. Nothing happens if you forget @p id.
  426.    */
  427.     void addConnection (int id, const char *signal,
  428.                         const QObject *receiver, const char *slot);
  429.   /**
  430.    * Enables/disables item.
  431.    */
  432.     void setItemEnabled( int id, bool enabled );
  433.  
  434.   /**
  435.    * Sets the icon for a button.
  436.    *
  437.    * Can be used while button is visible.
  438.    */
  439.     void setButtonIcon( int id, const QString& _icon );
  440.  
  441.   /**
  442.    * Sets button pixmap.
  443.    *
  444.    * Can be used while button is visible.
  445.    */
  446.     void setButtonPixmap( int id, const QPixmap& _pixmap );
  447.  
  448.   /**
  449.    * Sets a button icon from a QIconSet.
  450.    *
  451.    * Can be used while button is visible.
  452.    */
  453.     void setButtonIconSet( int id, const QIconSet& iconset );
  454.  
  455.   /**
  456.    * Sets a delayed popup for a button.
  457.    *
  458.    * Delayed popup is what you see in
  459.    * Netscape Navigator's Previous and Next buttons: If you click them you
  460.    * go back
  461.    * or forth. If you press them long enough, you get a history-menu.
  462.    * This is exactly what we do here.
  463.    *
  464.    * You will insert a normal button with connection (or use signals from
  465.    * toolbar):
  466.    * \code
  467.    * bar->insertButton(icon, id, SIGNAL(clicked ()), this,
  468.    *                   SLOT (slotClick()), true, "click or wait for popup");
  469.    * \endcode
  470.    * And then add a delayed popup:
  471.    * \code
  472.    * bar->setDelayedPopup (id, historyPopup);
  473.    * \endcode
  474.    *
  475.    * Don't add delayed popups to buttons which have normal popups.
  476.    *
  477.    * You may add popups which are derived from QPopupMenu. You may
  478.    * add popups that are already in the menu bar or are submenus of
  479.    * other popups.
  480.    */
  481.     void setDelayedPopup (int id , QPopupMenu *_popup, bool toggle = false);
  482.  
  483.   /**
  484.    * Turns a button into an autorepeat button.
  485.    *
  486.    * Toggle buttons, buttons with menus, or
  487.    * buttons with delayed menus cannot be made into autorepeat buttons.
  488.    * Moreover, you can and will receive
  489.    * only the signal clicked(), but not pressed() or released().
  490.    * When the user presses this button, you will receive the signal clicked(),
  491.    * and if the button is still pressed after some time,
  492.    * you will receive more clicked() signals separated by regular
  493.    * intervals.  Since this uses QButton::setAutoRepeat() ,
  494.    * I can't quantify 'some'.
  495.    */
  496.     void setAutoRepeat (int id, bool flag=true);
  497.  
  498.  
  499.   /**
  500.    * Turns button into a toggle button if @p flag is true.
  501.    */
  502.     void setToggle (int id, bool flag = true);
  503.  
  504.   /**
  505.    * Toggles a togglebutton.
  506.    *
  507.    * If the button is a toggle button  (see setToggle())
  508.    * the button state will be toggled. This will also cause the toolbar to
  509.    * emit the signal KButton::toggled() with parameter @p id. You must connect to
  510.    * this signal, or use addConnection() to connect directly to the
  511.    * button signal KButton::toggled().
  512.    */
  513.     void toggleButton (int id);
  514.  
  515.   /**
  516.    * Sets a toggle button state.
  517.    *
  518.    * If the button is a toggle button (see setToggle())
  519.    * this will set its state flag. This will also emit the signal
  520.    * KButton::toggled().
  521.    *
  522.    * @see setToggle()
  523.    */
  524.     void setButton (int id, bool flag);
  525.  
  526.   /**
  527.    * Returns @p true if button is on and is a toggle button
  528.    * @return @p true if button is on and is a toggle button
  529.    * @see setToggle()
  530.    */
  531.     bool isButtonOn (int id) const;
  532.  
  533.   /**
  534.    * Sets the text of a line editor.
  535.    *
  536.    * Cursor is set at end of text.
  537.    */
  538.     void setLinedText (int id, const QString& text);
  539.  
  540.   /**
  541.    * Returns the line editor text.
  542.    * @return the line editor text.
  543.    */
  544.     QString getLinedText (int id) const;
  545.  
  546.   /**
  547.    * Inserts @p text in combobox @p id at position @p index.
  548.    */
  549.     void insertComboItem (int id, const QString& text, int index);
  550.  
  551.     /**
  552.    * Inserts @p list in combobox @p id at position @p index.
  553.    */
  554.     void insertComboList (int id, const QStringList &list, int index);
  555.  
  556.   /**
  557.    * Removes item @p index from combobox @p id.
  558.    */
  559.     void removeComboItem (int id, int index);
  560.  
  561.   /**
  562.    * Sets item @p index to be current item in combobox @p id.
  563.    */
  564.     void setCurrentComboItem (int id, int index);
  565.  
  566.   /**
  567.    * Changes item @p index in combobox @p id to text.
  568.    *
  569.    * @p index = -1 refers current item (one displayed in the button).
  570.    */
  571.     void changeComboItem  (int id, const QString& text, int index=-1);
  572.  
  573.   /**
  574.    * Clears the combobox @p id.
  575.    *
  576.    * Does not delete it or hide it.
  577.    */
  578.     void clearCombo (int id);
  579.  
  580.   /**
  581.    * Returns text of item @p index from combobox @p id.
  582.    * @return text of item @p index from combobox @p id.
  583.    *
  584.    * @p index = -1 refers to current item.
  585.    */
  586.  
  587.     QString getComboItem (int id, int index=-1) const;
  588.  
  589.     /**
  590.    * Returns a pointer to the combobox with @p id.
  591.    * @return a pointer to the combobox with @p id.
  592.    *
  593.    * Example:
  594.    * \code
  595.    * KComboBox *combo = toolbar->getCombo(combo_id);
  596.    * \endcode
  597.    * That way you can get access to other public methods
  598.    * that KComboBox provides.
  599.    */
  600.     KComboBox * getCombo(int id);
  601.  
  602.     /**
  603.    * Returns a pointer to KToolBarLined with @p id.
  604.    * @return a pointer to KToolBarLined with @p id.
  605.    *
  606.    * Example:
  607.    * \code
  608.    * KLineEdit * lined = toolbar->getKToolBarLined(lined_id);
  609.    * \endcode
  610.    * That way you can get access to other public methods
  611.    * that KLineEdit provides. KLineEdit is the same thing
  612.    * as QLineEdit plus completion signals.
  613.    */
  614.     KLineEdit * getLined (int id);
  615.  
  616.     /**
  617.    * Returns a pointer to KToolBarButton.
  618.    *
  619.    * Example:
  620.    * \code
  621.    * KToolBarButton * button = toolbar->getButton(button_id);
  622.    * \endcode
  623.    * That way you can get access to other public methods
  624.    * that KToolBarButton provides.
  625.    *
  626.    *  Using this method is not recommended.
  627.    */
  628.     KToolBarButton * getButton (int id);
  629.  
  630.     /**
  631.    * Align item to the right.
  632.    *
  633.    * This works only if toolbar is set to full width.
  634.    * @see setFullWidth()
  635.    */
  636.     void alignItemRight (int id, bool right = true);
  637.  
  638.     /**
  639.    * Returns a pointer to the widget corresponding to @p id.
  640.    * @return a pointer to the widget corresponding to @p id.
  641.    *
  642.    * Wrong ids are not tested.
  643.    * You can do with this whatever you want,
  644.    * except change its height (hardcoded). If you change its width
  645.    * you will probably have to call QToolBar::updateRects(true)
  646.    * @see QWidget
  647.    * @see updateRects()
  648.    */
  649.     QWidget *getWidget (int id); // ### KDE4: make this const!
  650.  
  651.     /**
  652.    * Set item autosized.
  653.    *
  654.    * This works only if the toolbar is set to full width.
  655.    * Only @p one item can be autosized, and it has to be
  656.    * the last left-aligned item. Items that come after this must be right
  657.    * aligned. Items that can be right aligned are Lineds, Frames, Widgets and
  658.    * Combos. An autosized item will resize itself whenever the toolbar geometry
  659.    * changes to the last right-aligned item (or to end of toolbar if there
  660.    * are no right-aligned items.)
  661.    * @see setFullWidth()
  662.    * @see alignItemRight()
  663.    */
  664.     void setItemAutoSized (int id, bool yes = true);
  665.  
  666.     /**
  667.    * Remove all items.
  668.    *
  669.    * The toolbar is redrawn after it.
  670.    */
  671.     void clear ();
  672.  
  673.     /**
  674.    * Remove item @p id.
  675.    *
  676.    * Item is deleted. Toolbar is redrawn after it.
  677.    */
  678.     void removeItem (int id);
  679.  
  680.     /**
  681.    * Remove item @p id.
  682.    *
  683.    * Item is deleted when toolbar is redrawn.
  684.    */
  685.     void removeItemDelayed (int id);
  686.  
  687.     /**
  688.    * Hide item @p id.
  689.    */
  690.     void hideItem (int id);
  691.  
  692.     /**
  693.    * Show item @p id.
  694.    */
  695.     void showItem (int id);
  696.  
  697.     /**
  698.    * Returns the index of the item @p id.
  699.    * @return the index of the item @p id.
  700.    * @since 3.2
  701.    */
  702.     int itemIndex (int id); // ### KDE4: make this const!
  703.  
  704.     /**
  705.    * Returns the id of the item at the given index.
  706.    * @since 3.2
  707.    */
  708.     int idAt(int index); // ### KDE4: make this const!
  709.  
  710.     /**
  711.    * Set toolbar to full parent size (default).
  712.    *
  713.    * In full size mode the bar extends over the parent's full width or height.
  714.    * If the mode is disabled the toolbar tries to take as much space as it
  715.    * needs without wrapping, but it does not exceed the parent box. You can
  716.    * force a certain width or height with setMaxWidth() or
  717.    * setMaxHeight().
  718.    *
  719.    * If you want to use right-aligned items or auto-sized items you must use
  720.    * full size mode.
  721.    */
  722.     void setFullSize(bool flag = true);
  723.  
  724.     /**
  725.    * Returns the full-size mode enabled flag.
  726.    * @return @p true if the full-size mode is enabled.
  727.    */
  728.     bool fullSize() const;
  729.  
  730.     /**
  731.    * Enable or disable moving of toolbar.
  732.    * @deprecated use setMovingEnabled(bool) instead.
  733.    */
  734.     void enableMoving(bool flag = true) KDE_DEPRECATED;
  735.  
  736.     /**
  737.    * Set position of toolbar.
  738.    * @see BarPosition()
  739.    */
  740.     void setBarPos (BarPosition bpos);
  741.  
  742.     /**
  743.    * Returns the toolbar position.
  744.    * @return position of toolbar.
  745.    */
  746.     BarPosition barPos() const;
  747.  
  748.   /**
  749.    * Show, hide, or toggle toolbar.
  750.    *
  751.    * This method is provided for compatibility only,
  752.    * please use show() and/or hide() instead.
  753.    * @see BarStatus
  754.    * @deprecated
  755.    */
  756.     bool enable(BarStatus stat) KDE_DEPRECATED;
  757.  
  758.   /**
  759.    * Use setMaximumHeight() instead.
  760.    * @deprecated
  761.    */
  762.     void setMaxHeight (int h) KDE_DEPRECATED;  // Set max height for vertical toolbars
  763.  
  764.   /**
  765.    * Returns the value set with setMaxHeight().
  766.    * @deprecated
  767.    * Use maximumHeight() instead.
  768.    * @return the value set with setMaxHeight().
  769.    */
  770.     int maxHeight() KDE_DEPRECATED;
  771.  
  772.   /**
  773.    * Use setMaximumWidth() instead.
  774.    * Set maximal width of horizontal (top or bottom) toolbar.
  775.    * @deprecated
  776.    */
  777.     void setMaxWidth (int dw) KDE_DEPRECATED;
  778.  
  779.   /**
  780.    * Returns the value set with setMaxWidth().
  781.    * Use maximumWidth() instead.
  782.    * @return the value set with setMaxWidth().
  783.    * @deprecated
  784.    */
  785.     int maxWidth() KDE_DEPRECATED;
  786.  
  787.   /**
  788.    * Set title for toolbar when it floats.
  789.    *
  790.    * Titles are however not (yet)
  791.    * visible. You can't change toolbar's title while it's floating.
  792.    */
  793.     void setTitle (const QString& _title);
  794.  
  795.   /**
  796.    * Use setMovingEnabled(bool) instead.
  797.    * @deprecated
  798.    */
  799.     void enableFloating (bool flag) KDE_DEPRECATED;
  800.  
  801.   /**
  802.    * Set the kind of painting for buttons.
  803.    *
  804.    * Choose from:
  805.    * @li IconOnly (only icons),
  806.    * @li IconTextRight (icon and text, text is left from icons),
  807.    * @li TextOnly (only text),
  808.    * @li IconTextBottom (icons and text, text is under icons).
  809.    * @see IconText
  810.    *
  811.    */
  812.     void setIconText(IconText it);
  813.    // Note: don't merge with the next one, it breaks Qt properties
  814.  
  815.   /**
  816.    * Similar to setIconText(IconText it) but allows you to
  817.    * disable or enable updating.  If @p update is false, then the
  818.    * buttons will not be updated.  This is useful only if you know
  819.    * that you will be forcing an update later.
  820.    */
  821.     void setIconText(IconText it, bool update);
  822.  
  823.   /**
  824.    * Returns the current text style for buttons.
  825.    * @return the current text style for buttons.
  826.    */
  827.     IconText iconText() const;
  828.  
  829.   /**
  830.    * Set the icon size to load. Usually you should not call
  831.    * this, the icon size is taken care of by KIconLoader
  832.    * and globally configured.
  833.    * By default, the toolbar will load icons of size 32 for main
  834.    * toolbars and 22 for other toolbars
  835.    * @see KIconLoader.
  836.    *
  837.    * @param size The size to use
  838.    */
  839.     void setIconSize(int size);
  840.     // Note: don't merge with the next one, it breaks Qt properties
  841.  
  842.   /**
  843.    * Same as setIconText(int size) but allows you
  844.    * to disable the toolbar update.
  845.    *
  846.    * @param size   The size to use
  847.    * @param update If true, then the toolbar will be updated after
  848.    *               this
  849.    */
  850.     void setIconSize(int size, bool update);
  851.  
  852.   /**
  853.    * Returns the current icon size for buttons.
  854.    * @return the current icon size for buttons.
  855.    */
  856.     int iconSize() const;
  857.  
  858.   /**
  859.    * Returns the default size for this type of toolbar.
  860.    * @return the default size for this type of toolbar.
  861.    */
  862.     int iconSizeDefault() const;
  863.  
  864.   /**
  865.    * This allows you to enable or disable the context menu.
  866.    *
  867.    * @param enable If false, then the context menu will be disabled
  868.    */
  869.     void setEnableContextMenu(bool enable = true);
  870.  
  871.   /**
  872.    * Returns the context menu enabled flag
  873.    * @return true if the context menu is disabled
  874.    */
  875.     bool contextMenuEnabled() const;
  876.  
  877.   /**
  878.    * This will inform a toolbar button to ignore certain style
  879.    * changes.  Specifically, it will ignore IconText (always IconOnly)
  880.    * and will not allow image effects to apply.
  881.    *
  882.    * @param id The button to exclude from styles
  883.    * @param no_style If true, then it is excluded (default: true).
  884.    */
  885.     void setItemNoStyle(int id, bool no_style = true);
  886.  
  887.     void setFlat (bool flag);
  888.  
  889.   /**
  890.    * Returns the total number of items in the toolbar
  891.    * @return the total number of items in the toolbar
  892.    */
  893.     int count() const;
  894.  
  895.   /**
  896.    * Instruct the toolbar to save it's current state to either the app
  897.    * config file or to the XML-GUI resource file (whichever has
  898.    * precedence).
  899.    */
  900.     void saveState(); // BIC: remove for KDE4? This doesn't appear to be used internally,
  901.                       // and apps use saveMainWindowSettings in KMainWindow anyway.
  902.  
  903.   /**
  904.    * Save the toolbar settings to group @p configGroup in @p config.
  905.    */
  906.     void saveSettings(KConfig *config, const QString &configGroup);
  907.  
  908.   /**
  909.    * Read the toolbar settings from group @p configGroup in @p config
  910.    * and apply them. Even default settings are re-applied if @p force is set.
  911.    */
  912.     void applySettings(KConfig *config, const QString &configGroup,bool force);
  913.     // KDE4 merge with force=false
  914.     void applySettings(KConfig *config, const QString &configGroup);
  915.  
  916.   /*
  917.    * Tell the toolbar what XML-GUI resource file it should use to save
  918.    * it's state.  The state of the toolbar (position, size, etc) is
  919.    * saved in KConfig files if the application does not use XML-GUI
  920.    * but if the app does, then it's saved the XML file.  This function
  921.    * allows this to happen.
  922.    *
  923.    * @param xmlfile The XML-GUI resource file to write to
  924.    * @param xml     The DOM document for the XML-GUI building
  925.    * @internal
  926.    */
  927.   //  void setXML(const QString& xmlfile, const QDomDocument& xml);
  928.  
  929.     void setXMLGUIClient( KXMLGUIClient *client );
  930.  
  931.   /**
  932.    * Assign a (translated) text to this toolbar. This is used
  933.    * for the tooltip on the handle, and when listing the toolbars.
  934.    */
  935.     void setText( const QString & txt );
  936.  
  937.   /**
  938.    * Returns the toolbar's text.
  939.    * @return the toolbar's text.
  940.    */
  941.     QString text() const;
  942.  
  943.     void setStretchableWidget( QWidget *w );
  944.     QSizePolicy sizePolicy() const;
  945.     bool highlight() const;
  946.     QSize sizeHint() const;
  947.     QSize minimumSizeHint() const;
  948.     QSize minimumSize() const;
  949.  
  950.     void hide();
  951.     void show();
  952.  
  953.     void updateRects( bool = false ) {}
  954.  
  955.     /**
  956.      * Load state from an XML element, called by KXMLGUIBuilder
  957.      */
  958.     void loadState( const QDomElement &e );
  959.     /*
  960.      * Save state into an XML element, called by KXMLGUIBuilder
  961.      */
  962.     void saveState( QDomElement &e );
  963.  
  964.     /**
  965.      * @internal
  966.      */
  967.     void positionYourself( bool force = false);
  968.  
  969. signals:
  970.     /**
  971.      * Emitted when button @p id is clicked.
  972.      */
  973.     void clicked(int id);
  974.  
  975.     /**
  976.      * Emitted when button @p id is double-clicked.
  977.      *
  978.      * Note: you will always
  979.      * recive two clicked() , pressed() and released() signals.
  980.      * There is no way to avoid it - at least no easy way.
  981.      * If you need to resolve this all you can do is set up timers
  982.      * which wait for QApplication::doubleClickInterval() to expire.
  983.      * If in that time you don't get this signal, you may belive that
  984.      * button was only clicked and not double-clicked.
  985.      * And please note that butons with popup menus do not emit this signal,
  986.      * but those with delayed popup do.
  987.      */
  988.     void doubleClicked (int id);
  989.  
  990.     /**
  991.      * Emitted when button @p id is pressed.
  992.      */
  993.     void pressed(int);
  994.  
  995.     /**
  996.      * Emits when button @p id is released.
  997.      */
  998.     void released(int);
  999.  
  1000.     /**
  1001.      * Emitted when a toggle button changes state.
  1002.      *
  1003.      * Emitted also if you change state
  1004.      * with setButton() or toggleButton()
  1005.      * If you make a button normal again, with
  1006.      * setToggle(false), this signal won't
  1007.      * be emitted.
  1008.      */
  1009.     void toggled(int);
  1010.  
  1011.     /**
  1012.      * This signal is emitted when item @p id gets highlighted/unhighlighted
  1013.      * (i.e when mouse enters/exits).
  1014.      *
  1015.      * Note that this signal is emitted from
  1016.      * all buttons (normal, disabled and toggle) even when there is no visible
  1017.      * change in buttons (i.e., buttons do not raise when mouse enters).
  1018.      * The parameter @p isHighlighted is @p true when mouse enters and @p false when
  1019.      * mouse exits.
  1020.      */
  1021.     void highlighted(int id, bool isHighlighted);
  1022.  
  1023.     /**
  1024.      * This signal is emitted when item @p id gets highlighted/unhighlighted
  1025.      * (i.e when mouse enters/exits).
  1026.      *
  1027.      * Note that this signal is emitted from
  1028.      * all buttons (normal, disabled and toggle) even when there is no visible
  1029.      * change in buttons (i.e., buttons do not raise when mouse enters).
  1030.      */
  1031.     void highlighted(int id );
  1032.  
  1033.     /**
  1034.      * Emitted when toolbar changes position, or when
  1035.      * an item is removed from toolbar.
  1036.      *
  1037.      * If you subclass KMainWindow and reimplement
  1038.      * KMainWindow::resizeEvent() be sure to connect to
  1039.      * this signal. Note: You can connect this signal to a slot that
  1040.      * doesn't take parameter.
  1041.      */
  1042.     void moved( BarPosition );
  1043.  
  1044.     /**
  1045.      * This signal is emitted when toolbar detects changing of
  1046.      * following parameters:
  1047.      * highlighting, button-size, button-mode. This signal is
  1048.      * internal, aimed to buttons.
  1049.      * @internal
  1050.      */
  1051.     void modechange ();
  1052.  
  1053.     /**
  1054.      * This signal is emitted when the toolbar is getting deleted,
  1055.      * and before ~KToolbar finishes (so it's still time to remove
  1056.      * widgets from the toolbar).
  1057.      * Used by KWidgetAction.
  1058.      * @since 3.2
  1059.      */
  1060.     void toolbarDestroyed();
  1061.  
  1062. public:
  1063.     /**
  1064.      * Returns the global setting for "Highlight buttons under mouse"
  1065.      * @return global setting for "Highlight buttons under mouse"
  1066.      */
  1067.     static bool highlightSetting();
  1068.  
  1069.     /**
  1070.      * Returns the global setting for "Toolbars transparent when moving"
  1071.      * @return global setting for "Toolbars transparent when moving"
  1072.      */
  1073.     static bool transparentSetting();
  1074.  
  1075.     /**
  1076.      * Returns the global setting for "Icon Text"
  1077.      * @return global setting for "Icon Text"
  1078.      */
  1079.     static IconText iconTextSetting();
  1080.  
  1081. public slots:
  1082.     virtual void setIconText( const QString &txt )
  1083.     { QToolBar::setIconText( txt ); }
  1084.  
  1085. protected:
  1086.     void mousePressEvent( QMouseEvent * );
  1087.     void childEvent( QChildEvent *e );
  1088.     void showEvent( QShowEvent *e );
  1089.     void resizeEvent( QResizeEvent *e );
  1090.     bool event( QEvent *e );
  1091.     void applyAppearanceSettings(KConfig *config, const QString &_configGroup, bool forceGlobal = false);
  1092.     QString settingsGroup() const;
  1093.  
  1094. private slots:
  1095.     void rebuildLayout();
  1096.     void slotReadConfig ();
  1097.     void slotAppearanceChanged();
  1098.     void slotIconChanged(int);
  1099.     void slotRepaint();
  1100.     void toolBarPosChanged( QToolBar *tb );
  1101.     void slotContextAboutToShow();
  1102.     void slotContextAboutToHide();
  1103.     void widgetDestroyed();
  1104.  
  1105. private:
  1106.     void init( bool readConfig = true, bool honorStyle = false );
  1107.     void doConnections( KToolBarButton *button );
  1108.     void insertWidgetInternal( QWidget *w, int &index, int id );
  1109.     void removeWidgetInternal( QWidget *w );
  1110.     void getAttributes( QString &position, QString &icontext, int &index );
  1111.     int dockWindowIndex();
  1112.     KPopupMenu *contextMenu();
  1113.     void doModeChange();
  1114.  
  1115.     QMap<QWidget*, int > widget2id;
  1116.     typedef QMap<int, QWidget* > Id2WidgetMap;
  1117.     Id2WidgetMap id2widget;
  1118.     KPopupMenu *context;
  1119.     QPtrList<QWidget> widgets;
  1120.     QTimer *layoutTimer;
  1121.     QGuardedPtr<QWidget> stretchableWidget, rightAligned;
  1122. protected:
  1123.     virtual void virtual_hook( int id, void* data );
  1124. private:
  1125.     KToolBarPrivate *d;
  1126. };
  1127.  
  1128. #endif
  1129.